package com.ruoyi.demo.config;

import com.ruoyi.demo.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/app/**")  // 拦截所有/app/下的请求
                .excludePathPatterns(        // 排除不需要拦截的路径
                        "/app/user/login",   // 登录接口
                        "/app/goods/**",        // 商品接口
                        "/app/user/wx/openid"   // 获取微信openid
                );
    }
}
